package com.education.welco.controller;


import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.LPaper;
import com.education.welco.service.ILPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 试卷 信息操作处理
 *
 * @author d
 * @date 2020-05-08
 */
@RestController
@RequestMapping("/lPaper")
public class LPaperController  {

   @Autowired
    private ILPaperService paperService;

   @GetMapping("list")
    public ApiReturnObject list(LPaper lPaper){
       List<LPaper> lPapers = paperService.selectLPaperList(lPaper);
       return new ApiReturnObject("200","查询成功",lPapers);
   }

   @PostMapping("add")
    public ApiReturnObject add(@RequestBody LPaper lPaper){
       lPaper.setCreateTime(new Date());
       paperService.insertLPaper(lPaper);
       return new ApiReturnObject("200","添加成功","");
   }

   @PostMapping("update")
    public ApiReturnObject update(@RequestBody LPaper lPaper ){
       if(lPaper.getId() != null ){
           paperService.updateLPaper(lPaper);
           return new ApiReturnObject("200","修改成功","");
       }
       return new ApiReturnObject("201","缺少参数id","");
   }

   @PostMapping("del")
    public ApiReturnObject del(@RequestBody LPaper lPaper){
       if(lPaper.getId() != null){
           paperService.deleteLPaperById(lPaper.getId());
           return new ApiReturnObject("200","删除成功","");
       }
       return new ApiReturnObject("201","缺少参数","");
   }

}